home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / DLL Source Code / SampKKK.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-27  |  2.5 KB  |  92 lines  |  [TEXT/MPS ]

  1. /************************************************/
  2. /*                  Sample DLL's                */
  3. /*       Copyright © Vincent Parsons 1989.      */
  4. /************************************************/
  5. /*    DLL code for MPW C 3.0 or THINK C 4.0     */
  6. /*       with Excel for the Macintosh 2.2       */
  7. /*             and Microsoft C 5.1              */
  8. /*          with Excel for Windows 2.1          */
  9. /************************************************/
  10. /* SampKKK is an example of two data type K     */
  11. /* inputs and one data type K output.  The      */
  12. /* output is the complex product of the         */
  13. /* two type K inputs intrepreted as complex     */
  14. /* numbers.                                     */
  15. /************************************************/
  16. /*   =REGISTER("SampDLLs","SampKKK","KKK")      */
  17. /*   for both the Mac and the PC.               */
  18. /************************************************/
  19. /*
  20.    Note that the complex number is passed
  21.    as FP * c1 on the Mac and on the PC.
  22.  
  23.    The function type is pascal FP * on the Mac
  24.    and FP far * far pascal on the PC.
  25.  
  26.    On the Mac the returned value is c1 (the
  27.    pointer to the FP result) and the answer
  28.    has been stored in the Excel buffer used
  29.    by the input variable.
  30.  
  31.    On the PC the answer is stored in a static
  32.    variable and the returned value is a pointer
  33.    to that static value.
  34.  
  35.    This was done so the REGISTER command was
  36.    the same in the PC and the Mac.
  37. */
  38. /************************************************/
  39.  
  40. #include "DLL.h"
  41.  
  42. typedef struct fp {
  43.         unsigned short rows;
  44.         unsigned short columns;
  45.         double64 array[2];
  46. } FP;
  47.  
  48. #if applec
  49. #include <Types.h>
  50.  
  51. #elif MSDOS
  52. #include <windows.h>
  53.  
  54. #endif
  55.  
  56. #if THINK_C
  57. pascal FP * main(FP * k1, FP * k2);     /* prototype */
  58.  
  59. pascal FP * main(k1, k2)
  60. FP * k1;
  61. FP * k2;
  62.  
  63. #elif applec
  64. pascal FP * SampKKK(FP * k1, FP * k2)
  65.  
  66. #elif MSDOS
  67. FP far * far pascal SampKKK(FP far * k1, FP far * k2)
  68. #endif
  69. {
  70. #if applec | THINK_C
  71.    FP answer;           /* Automatic variable */
  72. #elif MSDOS
  73.    static FP answer;
  74. #endif
  75.  
  76.    answer.array[0] = (k1->array[0] * k2->array[0]) - (k1->array[1] * k2->array[1]);
  77.    answer.array[1] = (k1->array[0] * k2->array[1]) + (k1->array[1] * k2->array[0]);
  78.    answer.rows = k1->rows;
  79.    answer.columns = k1->columns;
  80.  
  81. #if applec | THINK_C
  82.    * k1 = answer;     /* Store value in Excel data buffer since static */
  83.                             /* variables are not permitted in MPW code resources */
  84.         return ( k1 );
  85. #elif MSDOS
  86.    return( (FP far *)&answer );
  87. #endif
  88. }
  89.  
  90. /************************************************/
  91.  
  92.